--大秘境
---@class Billboard_ChaosPanel : UIComponentBase
local MythicPanel = Class("MythicPanel", UIComponentBase)
local t = MythicPanel

function t:OnCreate()
    self.rankList = self:GetList("ranklist")
    self.btnRank = self:GetChild("LookRank")
    self.btnReward = self:GetChild("RewardGet")
    self.changeTxt = self:GetChild("change")
    self.titleText = self:GetChild("TowerTitle")
    self:RegisterOnClick(self.btnRank, self.ClickRank)
    self:RegisterOnClick(self.btnReward, self.ClickReward)
    self:SetDynamicList(self.rankList, self.ItemRender, self, true)
    self.playerDataList = {}
    self.rankList.numItems = 3
    self.rankType = logicMgr.NoticeManager.RankType.Chaos
end

function t:OnEnable()
    local infoList = logicMgr.TrialsManager.GetWorkRank();
    table.clear(self.playerDataList)
    if infoList and table.getn(infoList) > 0 then
        for i = 1, 3 do
            if i <= #infoList then
                table.insert(self.playerDataList, infoList[i])
            else
                break
            end
        end
    end
    self.rankList.numItems = 3
    self.changeTxt.text = logicMgr.NoticeManager.GetAbnormalChangeStr(self.rankType)
    self.titleText.text = getLanguage("FunctionName305")
    self:RefreshReward()
end
function t:OnDisable()
end
function t:OnDestroy()
    self.playerDataList = nil
end

function t:ItemRender(index, go)
    local data = self.playerDataList[index]
    local icon = go:GetChild("head"):GetChild("head"):GetChild("HeadIcon")
    local frame = go:GetChild("head"):GetChild("frame")
    go.onClick:Clear()
    if data then
        self:SetPlayerIcon(icon, data.playerShowInfo.pic,frame,data.playerShowInfo.picFrame)
        go:GetChild("Name").text = data.playerShowInfo.name
        self:RegisterOnClick(go, self.ClickIcon, self, index)
    else
        icon.url = EnumConst.AtlasPath.CommonUI.."icon_hero_kb91"
        frame.url = ""
        go:GetChild("Name").text = getLanguage("BillboardRankNeedPlayer")
    end
    go:GetController("ctrlRank").selectedIndex = index - 1
end

function t:RefreshReward()
    self.btnReward.visible = logicMgr.NoticeManager.HasReward(self.rankType)
end
function t:ClickRank()
    logicMgr.UIShowManager.ShowUIMythicRank()
end
function t:ClickReward()
    NoticeHandler.ReqChangeAwardByType(self.rankType)
end
function t:GetAllData()
    local infoList = logicMgr.TrialsManager.GetWorkRank();
   -- local infos = logicMgr.NoticeManager.GetMainRanksByType(self.rankType)
    --local tb = infos.ranks
    table.clear(self.playerDataList)
    for i = 1, 3 do
        if i <= #infoList then
            table.insert(self.playerDataList, infoList[i])
        else
            break
        end
    end
    if #self.playerDataList == 0 then
        self.changeTxt.text = logicMgr.NoticeManager.GetChangeStr(self.rankType,NoticeManager.NO_MAIN_CHOOSE_TYPE)
    end
    self.rankList.numItems = math.min(#self.playerDataList + 3, 3)
end
function t:ClickIcon(index)
    local data = self.playerDataList[index]
    if not data then
        return
    end
    --if tostring(data.playerShowInfo.playerId) ~= logicMgr.HeroManager.GetRoleId() then
        roleInfoHandler.sendreqOtherRoleInfo(data.playerShowInfo.playerId);
    --end
end
return t